package org.apmap.servlets;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.apmap.base.Main;
import org.apmap.base.Office;
import org.apmap.forms.OfficeForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteOfficeAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
        OfficeForm form = (OfficeForm) actionForm;

        Session session = Main.getSession();
        session.beginTransaction();

        Office office = (Office) session.load(Office.class, form.getOfficeid());
        session.delete(office);

        session.getTransaction().commit();
        session.close();

        request.setAttribute("message", "Объект удален.");
        return mapping.findForward("propertiesmessage");
    }

}